package cn.wolfcode.car.controller;

import cn.wolfcode.car.domain.*;
import cn.wolfcode.car.domain.Checking;
import cn.wolfcode.car.qo.CheckingQueryObject;
import cn.wolfcode.car.service.ICheckingService;
import cn.wolfcode.car.service.IDepartmentService;
import cn.wolfcode.car.service.ITypeservice;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import result.JsonResult;

import java.util.List;

@Controller
@RequestMapping("/checking")
public class CheckingController {
    @Autowired
    private ICheckingService iCheckingService;
    @Autowired
    private IDepartmentService iDepartmentService;
    @Autowired
    private ITypeservice iTypeservice;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo")CheckingQueryObject qo){
        PageInfo<Checking> list =  iCheckingService.selectForPage(qo);
        System.out.println("!!!!!!!!!!!!!!!!!!!!!!!"+list);
        model.addAttribute("result",list);
        return "checking/list";
    }
    @PostMapping("/saveOrUpdate")
    public String saveOrUpdate(Checking checking){
        if (checking.getId()==null){
            iCheckingService.save(checking);
        }else{
            iCheckingService.update(checking);
        }
        return "redirect:/checking/list";
    }

    @GetMapping("/delete")
    @ResponseBody
    public JsonResult delete(Long id ) {
        iCheckingService.delete(id);
        return JsonResult.success(null);
    }
    @RequestMapping("/input")
    public String input(Long id,Model model){
        if (id!=null){
            //编辑
            Checking checking = iCheckingService.selectBychencingId(id);
            System.out.println("7777777777777777777777777777777"+checking);
            model.addAttribute("currentChecking",checking);
        }
        List<Type> list = iTypeservice.list();
        System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!"+list);
        model.addAttribute("type",list);
        List<Department>departments = iDepartmentService.listAll();
        model.addAttribute("departments",departments);

        return "checking/input";
    }
}
